﻿<html xmlns:th="http://www.thymeleaf.org">
<head>
    <!--资源获取-->
    <base th:href="|${#request.getContextPath()}/|">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="static/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="static/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="static/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--layui-->
    <link rel="stylesheet" type="text/css" href="static/layui/css/layui.css"/>
    <script type="text/javascript" src="static/layui/layui.js"></script>
    <title>资讯列表</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    首页
    <span class="c-gray en">&gt;</span>
    博客
    <span class="c-gray en">&gt;</span>
    博客正文
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon layui-icon-refresh"></i> </a>

</nav>
<div class="layui-bg-gray" style="padding: 30px;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">
            <div class="layui-panel">
                <div style="padding: 10px 30px;">
                    <!--正文sts-->
                    <header style="background-color: #fff;margin-bottom: 1px;border-bottom: none;">
                        <h1 th:text="${post.posttitle}"></h1>
                        <p  style="color: #dddddd"><span th:text="${post.username}"></span> <span th:text="${post.posttime}">时间</span></p>
                    </header>
                    <hr>
                    <article style="background-color: #fff;padding: 10px 0px;">
                        <p th:text="${post.posttext}"></p>
                        <div style="float:right" >
                            <a href="javascript:;"><i name="pl" class="layui-icon layui-icon-reply-fill"></i></a><!--评论-->
                            <a href="javascript:;"><i name="dzpost" class="layui-icon layui-icon-praise"></i></a><!--点赞-->
                            <a th:if="${post.userid eq session.session_user.uId || session.session_user.admin ==1}" href="javascript:;"><i th:value="${post.postid}" name="scpost" class="layui-icon layui-icon-close"></i></a><!--删除-->
                            <span id="spandzcount"></span>
                        </div>
                    </article>
                    <!--正文end-->
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-panel">
                <div style="padding: 10px 30px;">
                    <!--评论sts-->
                    <header style="background-color: #fff;margin-bottom: 1px;border-bottom: none;">
                        <h3>评论</h3>
                    </header>
                    <hr>
                    <article id="plnr" style="background-color: #fff">
                        <ul class="flow-default"  id="LAY_demo2"></ul>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">输入评论</label>
                            <div class="layui-input-block">
                                <textarea id="plrk" name="desc" placeholder="评论文章" class="layui-textarea"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <form class="layui-form" action="">
                                <button id="plplid" hidden="hidden"></button>
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </form>
                            </div>
                        </div>
                    </article>
                    <!--评论end-->
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript" src="static/lib/jquery/1.9.1/jquery.min.js"></script>

<script type="text/javascript" src="static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/lib/laypage/1.2/laypage.js"></script>

<script type="text/javascript" src="static/my/js/post.js"></script>
<script type="text/javascript" src="static/my/js/util.js"></script>
<script>



</script>

<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/lib/jquery.contextmenu/jquery.contextmenu.r2.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="static/lib/datatables/1.10.15/jquery.dataTables.min.js"></script>
<script type="text/javascript">
    var sessionuser = [[${session.session_user.uId}]];
    //手动加载
    layui.use(['flow','element'], function(){
        var flow = layui.flow;

        var element = layui.element;
        flow.load({
            elem: '#LAY_demo2' //流加载容器
            ,isAuto: false
            ,isLazyimg: true
            ,done: function(page, next){ //加载下一页
                setTimeout(function(){
                    var lis = [];
                    var pages;
                    $.ajax({
                        url: "post/postcm",
                        type: "GET",
                        async:false,
                        data: {
                            "page": page,
                            "limit":6,
                            "postid": [[${post.postid}]]
                        },
                        success: function (regas) {
                            pages = regas.count;
                            var i_shanchu ="";
                            for(var a of regas.data){
                                if(a.cmUser==sessionuser){
                                    i_shanchu='<i name ="scpl" value="'+a.cmUser+'" class="layui-icon layui-icon-close"></i>';
                                }else {
                                    i_shanchu='';
                                }
                                if(a.cmToUser!=null){
                                    lis.push('<li><p>'+a.cmUserName+'评论'+a.cmToUserName+':'+a.cm+'\n' +
                                        '<a style="float:right" href="javascript:;"><i name="plpl" value="user_'+a.cmUser+'_'+a.cmUserName+'" class="layui-icon layui-icon-reply-fill"></i></a><a style="float:right" href="javascript:;">'+i_shanchu+'</a><!--评论--></p></li>')
                                }else {
                                    lis.push('<li><p>'+a.cmUserName+'评论:'+a.cm+'\n' +
                                        '<a style="float:right" href="javascript:;"><i name="plpl" value="user_'+a.cmUser+'_'+a.cmUserName+'" class="layui-icon layui-icon-reply-fill"></i></a><a style="float:right" href="javascript:;">'+i_shanchu+'</a><!--评论--></p></li>')
                                }
                            }

                        }
                    })
                    next(lis.join(''), page < pages); //假设总页数为 6
                }, 500);
            }
        });

    });
    //表单
    layui.use(['form','element'], function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
           var plplid =$("#plplid").val();
           $.ajax({
               url: "post/insterPostcm",
               type: "POST",
               data: {
                   "cmUser": sessionuser,
                   "cmToUser":plplid,
                   "postId": [[${post.postid}]],
                   "cm": $("#plrk").val()
               },
               success: function (regas) {
                   location.reload();
               }
           })
            return false;
        });
    });
    $("i[name='pl']").click(function () {
        console.log("评论")
        $("#plrk").attr("placeholder","评论文章").focus();
        $("#plplid").val("");
    })
    $("i[name='scpost']").click(function () {
        console.log("删除")
        $.ajax({
            url: "post/deletePostDz",
            type: "Post",
            data: {
                "postId": [[${post.postid}]]
            },
            success: function (regas) {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        })
    })
    $("#plnr").on("click","i[name='plpl']",function () {
        var yongh = $(this).attr("value");
        $("#plrk").attr("placeholder","评论"+yongh.split("_")[2]).focus();
        $("#plplid").val(yongh.split("_")[1]);
    })
    $("i[name='dzpost']").on("click",function () {
        console.log("点赞post");
        $.ajax({
            url: "post/insterPostDz",
            type: "Post",
            data: {
                "postId": [[${post.postid}]],
                "userId":sessionuser
            },
            success: function (regas) {
                if(regas=="already"){
                    layer.msg('已收藏');
                }else{
                    layer.msg('已取消');
                }
                selectdzpost();
            }
        })
    })
    function selectdzpost() {
            $.ajax({
                url: "post/selectCountDz",
                type: "GET",
                data: {
                    "postId": [[${post.postid}]]
                },
                success: function (regas) {
                    $("spandzcount").html(regas)
                }
            })
    }

    selectdzpost();
</script>

</body>
</html>
